package site.jlopen.secret.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import site.jlopen.secret.client.SecretClientHttp;
import site.jlopen.secret.client.SecretReqUrl;
import site.jlopen.secret.common.SecretClientResponse;
import site.jlopen.secret.common.SecretReqBaseForm;
import site.jlopen.secret.config.SecretClientProperties;
import site.jlopen.secret.model.project.SecretProjectCreateReq;
import site.jlopen.secret.service.intf.SecretProjectManage;

public class SecretProjectImpl implements SecretProjectManage {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	private final SecretClientProperties clientProperties;
	
	public SecretProjectImpl(SecretClientProperties clientProperties) {
		this.clientProperties = clientProperties;
	}

	@Override
	public SecretClientResponse<String> create(SecretProjectCreateReq form) {
		logger.info("创建运算项目：{}", form);
		SecretClientHttp<String> clientRequest = new SecretClientHttp<String>(clientProperties);
		form.setAppId(clientProperties.getAppId());
		SecretClientResponse<String>  res = clientRequest.execute(SecretReqUrl.PROJECT_CREATE_URL, form);
		return res;
	}

	@Override
	public SecretClientResponse<String> finish(String projectCode) {
		logger.info("归档项目：projectCode：{}", projectCode);
		SecretClientHttp<String> clientRequest = new SecretClientHttp<String>(clientProperties);
		SecretReqBaseForm<String> form = new SecretReqBaseForm<String>()
		.add("projectCode", projectCode)
		.appId(clientProperties.getAppId());
		SecretClientResponse<String>  res = clientRequest.execute(SecretReqUrl.PROJECT_FINISH_URL, form);
		return res;
	}

	@Override
	public SecretClientResponse<String> addInvite(String projectCode, Long nodeId, Long dataId) {
		logger.info("添加项目合作方：projectCode：{}，nodeId：{}，dataId：{}", projectCode, nodeId, dataId);
		SecretClientHttp<String> clientRequest = new SecretClientHttp<String>(clientProperties);
		SecretReqBaseForm<String> form = new SecretReqBaseForm<String>()
		.add("projectCode", projectCode)
		.add("nodeId", nodeId)
		.add("dataId", dataId)
		.appId(clientProperties.getAppId());
		SecretClientResponse<String>  res = clientRequest.execute(SecretReqUrl.PROJECT_INVITE_URL, form);
		return res;
	}

}
